<!-- 用户管理 -->
<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!-- 用户列表 -->
      <el-col :lg="24" :xs="24">
        <div v-if="true" class="search-bar">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="创建时间">
              <el-date-picker
                v-model="queryParams.createTime"
                :editable="false"
                class="!w-[240px]"
                type="daterange"
                range-separator="~"
                start-placeholder="开始时间"
                end-placeholder="截止时间"
                value-format="YYYY-MM-DD"
              />
            </el-form-item>

            <el-form-item>
              <el-button type="primary" @click="handleQuery">
                <template #icon><Search /></template>
                搜索
              </el-button>
              <el-button @click="handleResetQuery">
                <template #icon><Refresh /></template>
                重置
              </el-button>
            </el-form-item>
          </el-form>
        </div>

        <el-card v-if="true" shadow="never" class="table-wrapper">
          <el-table
            v-loading="loading"
            :data="pageData"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" width="50" align="center" />
            <el-table-column
              key="id"
              label="编号"
              align="center"
              prop="id"
              width="80"
            />
            <el-table-column
              key="imageUrl"
              label="图片"
              align="center"
              prop="imageUrl"
              width="200"
            >
              <template #default="scope">
                <img
                  :src="scope.row.imageUrl"
                  width="100px"
                  height="100px"
                  alt="Girl has dropped her ice cream."
                />
              </template>
            </el-table-column>
            <el-table-column label="使用时间" align="center" prop="createdAt" />

            <el-table-column fixed="right" label="Operations" width="200">
              <template #default="scope">
                <el-button
                  link
                  type="primary"
                  size="small"
                  @click.prevent="deleteRow(scope.$index)"
                >
                  Remove
                </el-button>
              </template>
            </el-table-column>
          </el-table>

          <pagination
            v-if="total > 0"
            v-model:total="total"
            v-model:page="queryParams.pageNo"
            v-model:limit="queryParams.pageSize"
            @pagination="handleQuery"
          />
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
defineOptions({
  name: "UserImage",
  inheritAttrs: false,
});

import ResultImageAPI, {
  ResultImageVO,
  ResultImagePageQuery,
} from "@/api/system/resultImage";

const queryFormRef = ref(ElForm);

const loading = ref(false);
const removeIds = ref([]);
const total = ref(0);
const pageData = ref<ResultImageVO[]>();

/** 用户查询参数  */
const queryParams = reactive<ResultImagePageQuery>({
  pageNo: 1,
  pageSize: 10,
});

/** 查询 */
function handleQuery() {
  loading.value = true;
  ResultImageAPI.getList(queryParams)
    .then((data) => {
      pageData.value = data.list;
      total.value = data.totalCount;
    })
    .finally(() => {
      loading.value = false;
    });
}

/** 重置查询 */
function handleResetQuery() {
  queryFormRef.value.resetFields();
  queryParams.pageNo = 1;
  queryParams.createTime = undefined;
  handleQuery();
}

/** 行复选框选中记录选中ID集合 */
function handleSelectionChange(selection: any) {
  removeIds.value = selection.map((item: any) => item.id);
}

const deleteRow = (index: number) => {
  // pageData.value.splice(index, 1);
};

onMounted(async () => {
  handleQuery();
});
</script>
